﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace SuperMe
{
    public class SuperMe_DataMgr
    {
        // scen_part_defs 是 所有可以被定义的部件 , 包含  PlayerFaction , StartingAnimal , StartingThing_Defined , 以及 StatFactor
        public static IEnumerable<ScenPartDef> scen_part_defs;
        // stat_defs 是 所有可以定义StatFactor 的部件, 显然包含 StatDefOf 的所有内容.
        public static IEnumerable<StatDef> stat_defs;
        // has_def_scen_parts 是 已经被定义的部件 ScenPart , 包含 ScenPart_StatFactor 以及 ScenPart_ConfigPage 和 ScenPart_XXXXXX
        public static IEnumerable<ScenPart> has_def_scen_parts;
        //
        private static ScenPartDef StatFactor_of_ScenPartDef;

        public static void InitDef()
        {
            SuperMeMod.settings.LoadDef();
            scen_part_defs = DefDatabase<ScenPartDef>.AllDefs;
            stat_defs = DefDatabase<StatDef>.AllDefs;
            has_def_scen_parts = Find.Scenario.AllParts;
        }

        private static ScenPartDef _FindStatFactor()
        {
            foreach (ScenPartDef scen_part_def in scen_part_defs)
            {
                if (scen_part_def.defName == "StatFactor")
                {
                    return scen_part_def;
                }
            }
            return null;
        }

        public static ScenPartDef FindStatFactor()
        {
            if (StatFactor_of_ScenPartDef == null)
            {
                StatFactor_of_ScenPartDef = _FindStatFactor();
            }
            return StatFactor_of_ScenPartDef;
        }
        public static void PrintStatDef()
        {
            foreach (StatDef stat_def in SuperMe_DataMgr.stat_defs)
            {
                SuperMeDef.Log("StatDef Value :" + stat_def.defName + " , " + stat_def.description + " , " + stat_def.GetType().Name);
            }
        }
        public static void PrintAllParts()
        {
            foreach (ScenPart sp in SuperMe_DataMgr.has_def_scen_parts)
            {
                SuperMeDef.Log("Scene Parts:" + sp.Summary(Find.Scenario));
            }
        }
    }
}
